﻿using CPPEI.App.Console;
using CPPEI.BD.Contract;
using CPPEI.Coolzon.Common.Startup;
using CPPEI.Coolzon.Configuration;
using CPPEI.Net.UDP;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.BD.Agent
{
    class Program
    {
        static void Main(string[] args)
        {
            CPPEI.Coolzon.Common.Logger.InitByLogDirectory(string.Format("{0}\\logs\\", AppDomain.CurrentDomain.BaseDirectory));
            new App().Run(args);
        }
    }

    class App : XApplication
    {
        UDPClient _udpClient;

        public App()
            : base("CPPEI", "BD", "Agent", "Agent")
        {
            Settings.IsAutoRun = true;
            Settings.IsSingleton = true;
        }

        protected override bool OnXStartup(StartupParamCollection startupParams)
        {
            int port = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Port"]);
            //
            _udpClient = new UDPClient(port, new ResponseHandlerFactory());
            _udpClient.StartReceive();

            return true;
        }
    }
}
